package com.example.study.controller;


import net.sf.json.JSONArray;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by gl on 2017/5/24.
 */
@Controller
public class DemoController {
    //路径常量
    public static final String PATH ="demo/";

    @RequestMapping(value = "/demo/loadTree")
    public String loadTree(Model model){
        String[] city=new String[]{"西安市","咸阳市","渭南市"};
        String[] town1=new String[]{"新城区","碑林区","雁塔区"};
        String[] town2=new String[]{"武功县","梅县"};
        String[] town3=new String[]{"临渭区","开发区"};
        return PATH+"zTree";
    }

    @RequestMapping(value = "/get/data")
    @ResponseBody
    public JSONArray getZtreeData(){
        JSONArray result=new JSONArray();
        String s1 = "{id:1, pId:0, name:\"陕西省\" , open:false}";
        String s2 = "{id:2, pId:1, name:\"西安市\" , open:true}";
        String s3 = "{id:21, pId:2, name:\"雁塔区\" , open:true}";
        String s4 = "{id:4, pId:1, name:\"渭南市\" , open:true}";
        String s5 = "{id:41, pId:4, name:\"临渭区\" , open:true}";
        List<String> lstTree = new ArrayList<String>();
        lstTree.add(s1);
        lstTree.add(s2);
        lstTree.add(s3);
        lstTree.add(s4);
        lstTree.add(s5);
        result=JSONArray.fromObject(lstTree);
        return result;
    }
}
